<script>
var statusset=1;
var orderlist={};
var opencalulator=0;
var enablekeyborad=0;
var laststringinput="input.inpCsh";
var alldata=0;
var orderidset=0;
var questionidset=0;
function getorderdata(pageset)
{
var code='';
var checkname='';
var temp='';
$.post(serviceinfo+'getorderall', { page:pageset ,status:statusset}, function(data) { 

if(data.data.length)
{

$.each( data.data, function( key, value ) {

orderlist[value.orderid]=value;

if(value.newdate!=temp)
{

if(temp!='')
{
code += '</div>';

}
temp=value.newdate;



code += '<div class="wrprOutOrdLst">\n';
code += '<div class="dtOrdPOS">\n';
code += '<span class="clBg1 clTxtPOSB fs05">'+value.newdate+'</span>\n';
code += '</div>';
}


code += '<div class="wrpOrdLst clBd2 bdFull">\n';
code += '<div class="wrpOutOrdLst clBg2 clearfix">\n';
code += '<div class="wrprHdOrdLst clearfix">\n';



if(value.status=='1')
{
code += '<button onclick="openorder('+value.orderid+')" class="btnPOSW btnActOrd fs07">\n';
code += '<span class="icoPOS icoActOrd"></span>\n';
 code +='</button>\n';
}else if(value.status=='2')
{
code +='<div class="ordLstStts ordLstSttsPd"><span class="clTxtPOSW fs02">Paid</span></div>';

}
else if(value.status=='3')
{
code +='<div class="ordLstStts ordLstSttsCncl"><span class="clTxtPOSW fs02">Cancel</span></div>';

}


code += '<div class="wrpOutHdOrdLst clearfix">\n';
code += '<div class="wrpDateOrdLst">\n';
code += '<span class="fs02 clTxtPOSB">'+value.newdate+'</span>\n';
code += '<span class="fs02 clTxtPOSB">'+value.newtime+'</span>\n';
code += '</div>\n';
code += '<div class="wrpIDOrdLst">\n';
code += '<span class="clTxtPOSB fs09">'+value.orderid+'</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrprSaleOrdLst clBg3">\n';
code += '<div class="wrpCtmOrdLst clBg4 clearfix">\n';

code += '<div class="wrpInCtmOrdLst">\n';

if(value['userid']=='0')
{
code += '<img alt="img" src="/img/dfthmbuser.jpg">\n';

code += '<div class="wrpCtmName">\n';
code += '<div class="wrpInCtmName">\n';
checkname='Guest';
if(value['guestname']!='')
{
checkname=''+value['guestname']+' (Guest)';

}

code += '<div class="ctmName">\n';
code += '<span class="clTxtPOSB fs05 cutTxt">'+checkname+'</span>\n';
code += '</div>\n';


code += '</div>\n';
code += '</div>\n';
}else
{


code += '<img alt="img" src="'+value['user']['simguser']['newpath']+'">\n';

code += '<div class="wrpCtmName">\n';
code += '<div class="wrpInCtmName">\n';

code += '<div class="ctmName">\n';
code += '<span class="clTxtPOSB fs05 cutTxt">'+value['user']['displayname']+'</span>\n';
code += '</div>\n';
if(value['user']['disid']!='0'&&value['user']['tumid']!='0')
{
code += '<div class="ctmRoute clearfix">\n';
code += '<span class="icoPOS icoCtmRoute icoCtmRoute10"></span>\n';
code += '<span class="lctRoute clTxtPOSB cutTxt fs02">'+value['user']['disname']+' - '+value['user']['tumname']+'</span>\n';
code += '</div>\n';

}

code += '</div>\n';
code += '</div>\n';

}

code += '</div>\n';

code += '<div class="wrpExpOrd">\n';
code += '<button onclick="opensuborder('+value.orderid+')" class="btnPOSW btnExpOrd fs07">\n';
code += '<span class="icoPOS icoExpOrd"></span>\n';
code += '</button>\n';
code += '</div>\n';

code += '<div class="ttOrdLst">\n';
code += '<span class="clTxtPOSB fs09">'+value.sumall+' Baht</span>\n';
code += '</div>\n';

code += '</div>\n';

code += '<div class="wrpMnOrdLst" id="orderlist-'+value.orderid+'" style="display:none">\n';

$.each( value.suborder, function( key2, value2 ) {



code += '<div class="wrpOutMnOrdLst clBd2 clearfix">\n';
code += '<div class="wrpInMnOrdLst">\n';
code += '<div class="amtMnOrdLst">\n';
code += '<span class="clTxtPOSB fs05">'+value2.count+'</span>\n';
code += '</div>\n';
code += '<div class="wrpNameDtMuOrdLst">\n';
code += '<div class="nameMnOrdLst">\n';

if(value2.productid!='0')
{
code += '<span class="clTxtPOSB fs05">'+value2.productlist.title+'</span>\n';

}else
{

code += '<span class="clTxtPOSB fs05">'+value2.title+'</span>\n';
}



code += '</div>\n';
if(value2.note)
{
code += '<div class="dtMuOrdLst">\n';
code += '<span class="clTxtPOSB fs02">'+value2.note+'</span>\n';
code += '</div>\n';
}
code += '</div>\n';
code += '</div>\n';
code += '<div class="prcItmOrdLst">\n';

if(value2.price!='0.00')
{
code += '<span class="clTxtPOSB fs05">'+value2.price+' Baht</span>\n';
}else
{
code += '<span class="clTxtPOSB fs05">-'+value2.discount+' Baht</span>\n';

}




code += '</div>\n';
code += '</div>\n';



});

code += '</div>';


code += '</div>\n';
code += '</div>\n';
code += '</div>';







});

code += '</div>';

if(pageset==1)
{

var code2=' <div class="wrpPgPOS clearfix"></div>';
$('.wrprPgPOS').html(code2);
//console.log(data.count);
setpagination('.wrprPgPOS .wrpPgPOS',data.count,20,'getorderdata');

}


$('.wrprOrdLst').html(code);


}else
{
code=' <div class="noPOSData noDataPg"><span class="icoPOS icoNoOrd"></span><span class="fs05">No Order</span></div>';
$('.wrprOrdLst').html(code);

}

});

}
function setpagination(div,pageallset,rowpage,func)
{

$(div).pagination({
        items: pageallset,
        itemsOnPage: rowpage,
        cssStyle: 'light-theme',
        reverse:0,
        onPageClick: function(pageNumber, event) {
                   
                   
                   
                   
                   eval(func+"("+pageNumber+")")
       
                    // Callback triggered when a page is clicked
                    // Page number is given as an optional parameter
                }
    });

}
function opensuborder(orderid)
{

$('#orderlist-'+orderid).slideToggle("fast");


}
function changestatus(statussetnow)
{

statusset=statussetnow;

getorderdata(1);
}
function openorder(orderid)
{
orderidset=orderid;
$('.ovlTkPt.popActOrdPopPOS .clTxtPOSB').html('Order No : '+orderid);
$('.ovlTkPt.popActOrdPopPOS .btnAddMore').attr('onclick','redirectto(\'/pos/sell?orderid='+orderid+'\')');
$('.ovlTkPt.popActOrdPopPOS .btnPayOrd').attr('onclick','opensaveorder('+orderid+')');
$('.ovlTkPt.popActOrdPopPOS').fadeIn();

}
function opensaveorder(orderid)
{
var dataset=orderlist[orderid];
alldata=dataset.sumall;
orderidset=orderid;
$.post(serviceinfo+'checkquestiondata', { userid:dataset['orderid']}, function(data) { 


$('.wrprPopPay .ttlPopSale .clTxtPOSB.fs11').html('Total '+dataset.sumall+' Baht');
if(dataset.cash!='0.00')
{
if(dataset.cash.search(".00")!=-1)
{
$('.wrprPopPay .cashPopPay .inpCsh').val(parseInt(dataset.cash,10));


}else
{
$('.wrprPopPay .cashPopPay .inpCsh').val(dataset.cash);

}

}else
{
$('.wrprPopPay .cashPopPay .inpCsh').val('');

}
if(dataset.change!='0.00')
{


if(dataset.change.search(".00")!=-1)
{
$('.wrprPopPay .chngPopPay .clTxt3').html(parseInt(dataset.change,10));


}else
{

$('.wrprPopPay .chngPopPay .clTxt3').html(dataset.change);
}


}else
{
$('.wrprPopPay .chngPopPay .clTxt3').html('0');


}

if(data.data)
{
questionidset=data.data;
$('.wrprPopPay .ansq1[title="'+data.question.gender+'"]').addClass('qstTg');
$('.wrprPopPay .ansq2[title="'+data.question.age+'"]').addClass('qstTg');

}
else
{
questionidset=0;
$('.wrprPopPay .ansq1').removeClass('qstTg');
$('.wrprPopPay .ansq2').removeClass('qstTg');

}

$('.wrprPopPay input[name="guestname"]').val(dataset.guestname);

$('.wrprPopPay').fadeIn();




});

}
function calallchange()
{

var lasttext=$(laststringinput).val();

var testdata= lasttext.slice(-1);
//if(laststringinput!="input.tenderInp")
//{
//if(!$.isNumeric(testdata))
//{
//$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Can not calculate order');
//$('.micPopPOS.micWrn').fadeIn("fast");
//return false;
//}

//var numberdata= eval(lasttext);
//$(laststringinput).val(numberdata);
//opencalulator=0;
//enablekeyborad=0;
//$('.wrpPOS').removeClass('l337');
//$('.wrpOutPopSpc').removeClass('l170p');
//return false;
//}


if(alldata==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Order');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;

}


if(lasttext)
{
if(!$.isNumeric(testdata))
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Can not calculate order');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{

var numberdata= eval(lasttext);

if(numberdata<alldata)
{

$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Cash must be greater than or equal to the total price.');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;

}else
{
$(laststringinput).val(numberdata);
opencalulator=0;
enablekeyborad=0;
$('.wrpPOS').removeClass('l337');



$(".chngPopPay .clTxt3.fs11.clBd2.bdFull").html(numberdata-alldata);

}



}
}else
{

$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Input Number');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;

}


}
function settexttoinput(text)
{


var lasttext=$(laststringinput).val();
if(lasttext=='')
{
if(text=='0'||text=='00')
{

return true;
}


}


var testdata= lasttext.slice(-1);

if(text=='00')
{


if($.isNumeric(testdata)||text=='.')
{
    

}else
{

return true;
}



}



if(!$.isNumeric(testdata)&&!$.isNumeric(text))
{
return true;


}




$(laststringinput).val(lasttext+text);


}
 function opencalcutator()
{
opencalulator=1;
enablekeyborad=1;
$('.wrpPOS').addClass('l337');
$('.wrpOutPopPay').addClass('l170p');

}
function deletetexttoinput()
{

var lasttext=$(laststringinput).val();
lasttext=lasttext.substr(0,lasttext.length - 1);

$(laststringinput).val(lasttext);
}
function closecalcutator()
{
if(opencalulator==1)
{
opencalulator=0;
enablekeyborad=0;
$('.wrpPOS').removeClass('l337');
var lasttext=$(laststringinput).val();
if(lasttext!='')
{
var testdata= lasttext.slice(-1);
if(!$.isNumeric(testdata))
{
$(laststringinput).val('');


}else
{
var numberdata= eval(lasttext);

$(laststringinput).val(numberdata);
//calorder();

}
}
$('.wrpOutPopSpc').removeClass('l170p');

}

}
function saveorderalldata()
{
var arraydata={};
arraydata['orderid']=orderidset;
arraydata['status']=2;
arraydata['questionid']=questionidset;



if($(laststringinput).val()=='')
{

$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Input Cash');
$('.micPopPOS.micWrn').fadeIn("fast");
$(laststringinput).focus();
return false;
}else
{

arraydata['cash']=$(laststringinput).val();

}
if($('.wrprPopPay .chngPopPay .clTxt3').html()=='')
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Check Your Cash');
$('.micPopPOS.micWrn').fadeIn("fast");
$(laststringinput).focus();
return false;

}else
{

arraydata['change']=$('.wrprPopPay .chngPopPay .clTxt3').html();

}




if($('.wrprPopPay .ansq1.qstTg').length==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Gender');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{
arraydata['gender']=$('.wrprPopPay .ansq1.qstTg').attr('title');

}

if($('.wrprPopPay .ansq2.qstTg').length==0)
{
$('.micPopPOS.micWrn .clTxtPOSW.fs11').html('Please Choose Age');
$('.micPopPOS.micWrn').fadeIn("fast");
return false;
}else
{
arraydata['age']=$('.wrprPopPay .ansq2.qstTg').attr('title');

}

arraydata['guestname']=$('.wrprPopPay input[name="guestname"]').val();

$.post(serviceinfo+'changeorderstatus', arraydata, function(data) { 
getorderdata(1);
$('.wrprPopPay').fadeOut();
$('.ovlTkPt.popActOrdPopPOS').fadeOut();

});



}
function cancelorder()
{
var arraydata={};
arraydata['orderid']=orderidset;
arraydata['status']=3;

$.post(serviceinfo+'changeorderstatus', arraydata, function(data) { 
getorderdata(1);
$('.micPopPOS.micCf').fadeOut();
$('.ovlTkPt.popActOrdPopPOS').fadeOut();

});

}
getorderdata(1);


$(document).keydown(function(e){
      
     //console.log(e.which);
      /*
      8=== blackspace
      96 === 0
97 === 1
98 === 2
99 === 3
100 === 4
101 === 5
102 === 6
103 === 7
104 === 8
105 === 9

110 === .
107 === +
109 === -
106 === *
111 === */

    if(enablekeyborad)
    {
     if(e.which===8)
     {
     
     deletetexttoinput();
     e.preventDefault();
     
     }
     else if(e.which>95&&e.which<106)
     { 
     
     
     settexttoinput(''+(e.which-96));
     
     
     
     
     
     
     }
     else if(e.which===110)
     {
     
     settexttoinput('.');
     
     }
     else if(e.which===107)
     {
     
     settexttoinput('+');
     
     }
     else if(e.which===109)
     {
     
     settexttoinput('-');
     
     }
     else if(e.which===106)
     {
     
     settexttoinput('*');
     
     }
     else if(e.which===106)
     {
     
     settexttoinput('/');
     
     }
    else if(e.which===13)
    {
    calallchange();
    }
    
    
    }


      
      
    
    
    });

$("body").click(function(e) {

//console.log(e.target);

if(

   $(e.target).hasClass("wrprCalPOS")||
   $(e.target).hasClass("wrpCalPOS")||
   $(e.target).hasClass("spnCal")||
   $(e.target).hasClass("icoPOS")||
   $(e.target).hasClass("calPlus")||
   $(e.target).hasClass("calMinus")||
   $(e.target).hasClass("calErase")||
   $(e.target).hasClass("wrpOutMicPopPOS")||
   $(e.target).hasClass("clTxtPOSW")||
   $(e.target).hasClass("btnPOSW")||
   $(e.target).hasClass("tenderInp")||
   $(e.target).hasClass("closeCal")||
   $(e.target).hasClass("calAcp")||
   $(e.target).hasClass("cal00")||
   $(e.target).hasClass("cal0")||
   $(e.target).hasClass("calPoint")||
   $(e.target).hasClass("cal3")||
   $(e.target).hasClass("cal2")||
   $(e.target).hasClass("cal1")||
   $(e.target).hasClass("cal6")||
   $(e.target).hasClass("cal5")||
   $(e.target).hasClass("cal4")||
   $(e.target).hasClass("cal9")||
   $(e.target).hasClass("cal8")||
   $(e.target).hasClass("inpSpcPrc")||
   $(e.target).hasClass("inpCsh")||
   $(e.target).hasClass("cal7")
   
   
   
   
   
   )
  {
  
  
  }else
  {
  closecalcutator();
  
  }


});

$("input.inpCsh").focus(function(e) {

opencalcutator();
});




</script>
